<template>
  <div class="login-page">
    <div class="stars"></div>
    <div class="stars2"></div>
    <div class="login-info">
      <div class="info">
         <div class="title">{{appTitle}}</div>
        <div class="input login-user">
          <el-input
            v-model="form.userName" @keydown.enter="loginSubmit()"
            placeholder="请输入用户名"
            :prefix-icon="User"

          />
        </div>
        <div class="input login-password">
          <el-input
            type="password" @keydown.enter="loginSubmit()"
            v-model="form.password"
            placeholder="请输入密码"
            :prefix-icon="Unlock"
          />
        </div>
         <el-button  class="login-submit" @click="loginSubmit()" type="primary" :loading="false">立即登录</el-button>
      </div>
    </div>
  </div>
</template>

<script setup  lang="ts">
import { defineComponent, ref, reactive, onMounted, onActivated  } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { login } from "@/api/server_login";
import { ElMessage } from "element-plus";
import { User,Unlock } from '@element-plus/icons-vue';
// import homepage from '@/views/homepage/index.vue'
const router = useRouter();
const store = useStore();
const appTitle = import.meta.env.VITE_APP_TITLE;
const form = reactive({
  userName: "",
  password: "",
});
const loginSubmit = async () => {
  let { result ,token } = await login(form);
  if (result == "success") {
    window.localStorage.setItem("token", token);
    store.dispatch('getUser')
    ElMessage.success("登录成功");
    router.push({ name: "homepage" });

  }
};
onMounted(() => {
  let params = router.currentRoute.value.params;
  console.log('params',params);
});

</script>

<style scoped lang="scss">
.login-page {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
  overflow: hidden;
  position: absolute;

  .login-info {
    width: 450px;
    height: 470px;
    background: url(@/assets/login/bg.png) no-repeat center/contain;
    display: flex;
    align-items: center;
    justify-content: center;
    .info{
      padding: 0 100px;
    }
    .title{
      color: #ccf5ff;
      font-size:20px;
      margin: 20px 0;
    }
    .input{
      margin: 20px 0;
    }
    .login-submit{
      width: 100%;
    }
  }
}
</style>
